package com.ssd.config;


import com.ssd.interceptor.UserContextInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

/**
 * @author itcast
 */
@Configuration
public class UserContextConfiguration implements WebMvcConfigurer {
    @Resource
    private UserContextInterceptor userContextInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // token拦截器
        // 为所有请求路径添加用户上下文拦截器，以便在处理请求前进行统一的用户信息验证和设置
        // 但排除了登录、验证码和搜索用户工作等不需要验证的公共接口
        registry.addInterceptor(userContextInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns(ADMIN_EXCLUDE_PATH_PATTERNS);
    }


    //拦截的时候过滤掉swagger相关路径和登录相关接口
    private static final String[] ADMIN_EXCLUDE_PATH_PATTERNS = new String[]{
            "/swagger-ui.html",
            "/webjars/**",
            "/swagger-resources",
            "/v2/api-docs",
            "/customer/**",
            "/security/**",
            "/common/**",
            "/user/refresh/**",
            "/user/login"
            ,"/user/code/**"
            ,"/user/searchUserWork"
            , "/admin/index/login"
            ,"/admin/index/generateValidateCode"
            ,"/doc.html"};
}
